define(['../vendor/kobako/pixi/pixi.js', './world_logic.js', './logger.js', './player.js', './monster.js', '../components/single_player.js'], (PIXI, world_logic, Logger, players, monster_util, single_player) => {

    function run() {
        let Application = PIXI.Application,
            loader = PIXI.loader,
            resources = PIXI.loader.resources,
            Sprite = PIXI.Sprite,
            TextureCache = PIXI.utils.TextureCache,
            Rectangle = PIXI.Rectangle,
            Container = PIXI.Container,
            Text = PIXI.Text;

        let kobako = PIXI.kobako;

						/*
        async function set_up(_, resrc) {
            // Process map layers
            const layers = await kobako.loader.load_layers('assets/soto.png', 'assets/soto1.json', 2)

            // Process player
            const marisa = await kobako.loader.load_sheet_sprite('assets/marisa.png', 'assets/marisa.json')
            marisa.set_ani('down_stop')
            kobako.sprites.move_by_keyboard(marisa, 5, kobako.keyboard)
            kobako.sprites.ani_by_keyboard(marisa, kobako.keyboard)
            // kobako.sprites.emit_by_keyboard(marisa, ' ', kobako.keyboard)
            kobako.sprites.emit_by_mouse(marisa, app.stage)


            // Process bullets texture
            const texture_spawner = {
                bullet1: await kobako.loader.load_sheet_texture_spawner('assets/bullet1.png', 'assets/bullet1.json'),
                monster1: await kobako.loader.load_sheet_texture_spawner('assets/monster1.png', 'assets/monster1.json'),
            }



            const stones = layers[2]
            app.stage.addChild(layers[0]) //grass
            app.stage.addChild(layers[1]) //front of the stone
            app.stage.addChild(marisa) //player
            app.stage.addChild(stones) //stone
            app.stage.addChild(layers[3]) //back of the stone

            //Some special container
            const bullets = new PIXI.Container()
            app.stage.addChild(bullets)
            const booms = new PIXI.Container()
            app.stage.addChild(booms)
            const logger_container = new PIXI.Container()
            app.stage.addChild(logger_container)
            const monsters = new PIXI.Container()
            app.stage.addChild(monsters)

            

            //Setting the logger
            const view = new kobako.View(app, marisa)
            const logger = new Logger(5, logger_container, view)

            world_logic.init_weapon_system(marisa, texture_spawner, logger)
            marisa.weapon.switch_by_keyboard(kobako.keyboard)

            const world = { // Interactive objs
                player: marisa,
                stones: stones.children,
                bullets,
                booms, // boom anime sprite
                texture_spawner,
                logger,
                monsters,
                bound: app.stage.getBounds()
            }

            window.world = world

            kobako.sprites.facing_by_mouse(marisa, app.stage, view)

            const main_ticker = new kobako.Ticker(0.05)
            main_ticker.add(() => { // game loop
                world_logic.update(world)
            })
            main_ticker.add(() => { // after game loop
                view.adjust()
            })
            main_ticker.start()

            const anima_ticker = new kobako.Ticker(0.2)
            anima_ticker.add(() => {
                marisa.play()
                bullets.children.forEach(b => {
                    b.play()
                })
                booms.children.forEach(b => {
                    b.play()
                })
                monsters.children.forEach(m => {
                    m.play()
                })
            })
            anima_ticker.start()

            const log_ticker = new kobako.Ticker(1)
            log_ticker.add(() => {
                logger.update()
            })
            log_ticker.start()


            // World logic init
            world_logic.init(world)
        }
						*/

				async function load_marisa(){
					window.single_player = single_player
				  const marisa = await single_player.init()
					app.stage.addChild(marisa)
				}

        //Create a Pixi Application
        let app = new PIXI.Application({ width: 600, height: 600 });
        document.body.appendChild(app.view);
				
        window.app = app

        loader
            .add([]) //The resource will load then
            .load(load_marisa)
    }

    return { run }

})


